package tech.dx.springdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.dx.springdb.entity.ClassType;
import tech.dx.springdb.respository.ClassTypeRepository;
import tech.dx.springdb.service.ClassTypeService;

import java.util.Optional;

/**
 * @ClassName ClassTypeServiceImpl
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 12:20
 * @Version 1.0
 */
@Service
public class ClassTypeServiceImpl implements ClassTypeService {
    @Autowired
    private ClassTypeRepository classTypeRepository;
    @Override
    public Optional<ClassType> getById(long id) {
        return classTypeRepository.findById(id);
    }

    @Override
    public ClassType add(ClassType classtype) {
        ClassType save = classTypeRepository.save(classtype);
        return save;
    }

    @Override
    public ClassType update(ClassType classtype) {
        ClassType save = classTypeRepository.save(classtype);
        return save;
    }

    @Override
    public void del(long id) {
        classTypeRepository.deleteById(id);
    }

    @Override
    public boolean isExitById(long id) {
        Optional<ClassType> byId = classTypeRepository.findById(id);
        return byId.isPresent()?true:false;
    }
}
